package ru.sgu.acm.misc;

import java.util.Properties;
import java.io.IOException;

/**
 * Use this class to get constants and access configuration parameters.
 * @author Vitaly Goldshteyn VitalyGoldstein@gmail.com
 */
public class Constants {
    private static Long contesterId = null;

    private static final Properties properties = new Properties();

    private static final String PROPERTIES_FILE_NAME = "/pseudocontester.properties";

    public static String getJudgeMappingFileName() {
        return PROPERTIES_FILE_NAME;
    }

    public static String getDatabaseUrl() {
        return properties.getProperty("pseudocontester.database.url");
    }

    public static String getDatabaseUser() {
        return properties.getProperty("pseudocontester.database.user");
    }

    public static String getDatabasePassword() {
        return properties.getProperty("pseudocontester.database.password");
    }

    public static String getPendingStatus() {
        return properties.getProperty("pseudocontester.status.pending");
    }

    public static String getAcceptedStatus() {
        return properties.getProperty("pseudocontester.status.accepted");
    }

    public static String getTimeLimitStatus() {
        return properties.getProperty("pseudocontester.status.time-limit");
    }

    public static String getMomoryLimitStatus() {
        return properties.getProperty("pseudocontester.status.memory-limit");
    }

    public static String getRuntimeErrorStatus() {
        return properties.getProperty("pseudocontester.status.runtime-error");
    }

    public static String getCompilationErrorStatus() {
        return properties.getProperty("pseudocontester.status.compilation-error");
    }

    public static String getPresentationErrorStatus() {
        return properties.getProperty("pseudocontester.status.presentation-error");
    }

    public static String getWrongAnswerStatus() {
        return properties.getProperty("pseudocontester.status.wrong-answer");
    }

    public static String getUnknownErrorStatus() {
        return properties.getProperty("pseudocontester.status.unknown-error");
    }

    public static String getGlobalErrorStatus() {
        return properties.getProperty("pseudocontester.status.global-error");
    }

    public static String getTestingStatus() {
        return properties.getProperty("pseudocontester.status.testing");
    }

    public static long getPollPeriod() {
        return Long.parseLong(properties.getProperty("pseudocontester.poll-period"));
    }

    public static long getDefaultWaitTimeBeforeCheckingStatus() {
        return Long.parseLong(properties.getProperty("pseudocontester.wait-time-before-checking-status"));
    }

    public static long getWaitTimeBeforeCheckingStatusAgain() {
        return Long.parseLong(properties.getProperty("pseudocontester.wait-time-before-checking-status-again"));
    }

    public static long getMaximalRetryingTime() {
        return Long.parseLong(properties.getProperty("pseudocontester.maximal-retrying-time"));
    }

    public static String getSubmitPath() {
        return properties.getProperty("pseudocontester.submit.path");
    }

    public static String getXmlRpcUrl() {
        return properties.getProperty("pseudocontester.xml-rpc.url");
    }

    public static String getXmlRpcUser() {
        return properties.getProperty("pseudocontester.xml-rpc.user");
    }

    public static String getXmlRpcPassword() {
        return properties.getProperty("pseudocontester.xml-rpc.password");
    }

    public static long getContesterId() {
        if (contesterId == null) {
            contesterId = System.nanoTime() + Constants.class.hashCode() * 100009;
        }
        return contesterId;
    }

    static {
        try {
            properties.load(Constants.class.getResourceAsStream(PROPERTIES_FILE_NAME));
        } catch (IOException e) {
            throw new IllegalStateException("Unable to load properties from " + PROPERTIES_FILE_NAME + ".", e);
        }
    }
}
